import echarts from '@/utils/echarts/index.js'

/**
 * 绘制折线图
 * @param {optionObj} optionObj - 饼状图配置对象
 * 
 * @typedef {Object} optionObj
 * @property {string} dom - 图表容器的 DOM 选择器
 * @property {Array} data - 饼状图数据数组
 * 
 * @returns {Object} myChart - echarts 实例
 */
export function drawPieChart(optionObj) {
    const myChart = echarts.init(optionObj.dom)
    const option = {
        color: ['#3F8CFF', '#FFD023', '#F0F6FF'],
        tooltip: {
            trigger: 'item'
        },
        chart: {
            padding: [0, 0, 0, 0] // 设置边距为 0
        },
        legend: {
            left: 'center',
            bottom: '5%',
            icon: 'circle',
        },
        series: [
            {
                type: 'pie',
                top: '-15%',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                label: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    label: {
                        show: true,
                    }
                },
                labelLine: {
                    show: false
                },
                data: optionObj.data
            }
        ]
    };
    myChart.setOption(option)
    return myChart
}